package com.houdoudou.customer.common;

import com.houdoudou.customer.R;


import android.content.Context;  
import android.graphics.Color;  
import android.util.AttributeSet;  
import android.view.LayoutInflater;  
import android.view.MotionEvent;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.ImageView;  
import android.widget.LinearLayout;  
import android.widget.TextView;  

public class ImageText extends LinearLayout {

	 private Context mContext = null;  
	    private ImageView mImageView = null;  
	    private TextView mTextView = null;  
	//    private final static int DEFAULT_IMAGE_WIDTH = 64;  
	 //   private final static int DEFAULT_IMAGE_HEIGHT = 64;  
	    private final static int DEFAULT_IMAGE_WIDTH = 100;  
        private final static int DEFAULT_IMAGE_HEIGHT = 100;  
	    private int CHECKED_COLOR = Color.rgb(29, 118, 199); //选中蓝色  
	    private int UNCHECKED_COLOR = Color.rgb(128,128,128);   //自然灰色  
	    public ImageText(Context context) {  
	        super(context);  
	        // TODO Auto-generated constructor stub  
	        mContext = context;  
	    }  
	  
	    public ImageText(Context context, AttributeSet attrs) {  
	        super(context, attrs);  
	        // TODO Auto-generated constructor stub  
	        mContext = context;  
	        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
	        View parentView = inflater.inflate(R.layout.image_text_layout, this, true);  
	        mImageView = (ImageView)findViewById(R.id.image_iamge_text);  
	        mTextView = (TextView)findViewById(R.id.text_iamge_text);  
	        
	        BadgeView bg= new BadgeView(mContext,mImageView);
	        bg.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
	        bg.setBadgeMargin(1);
	        bg.setTextSize(8);
	        bg.setText(" ");
	        bg.show();
	        bg.hide();
	    }  
	    
	    
	    public void setImage(int id){  
	        if(mImageView != null){  
	        	//System.out.println("-----------id--------------"+id);
	          mImageView.setImageResource(id);  
	        //  System.out.println("-----------id--------------"+id);
	        	//  mImageView.setImageResource(R.drawable.ic_launcher);  
	         setImageSize(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);  
	        }  
	    }  
	  
	    public void setText(String s){  
	        if(mTextView != null){  
	            mTextView.setText(s);  
	         //   mTextView.setTextColor(UNCHECKED_COLOR);  
	        }  
	    }
	    
	    public void setTextChoosed(boolean choosed){
	    	if(choosed){
	    		mTextView.setTextColor(CHECKED_COLOR);  
	    	}else{
	    		 mTextView.setTextColor(UNCHECKED_COLOR);  
	    	}
	    }

	    @Override  
	    public boolean onInterceptTouchEvent(MotionEvent ev) {  
	        // TODO Auto-generated method stub  
	        return true;  
	    }  
	    
	    private void setImageSize(int w, int h){  
	        if(mImageView != null){  
	            ViewGroup.LayoutParams params = mImageView.getLayoutParams();  
	            params.width = w;  
	            params.height = h;  
	            mImageView.setLayoutParams(params);  
	        }  
	    }  
	    /* 重写这一段。
	     *    public void setChecked(int itemID){  
	     if(mTextView != null){  
	            mTextView.setTextColor(CHECKED_COLOR);  
	        }  
	        int checkDrawableId = -1;  
	        switch (itemID){  
	        case Constant.BTN_FLAG_MESSAGE:  
	            checkDrawableId = R.drawable.order_selected;  
	            break;  
	        case Constant.BTN_FLAG_CONTACTS:  
	            checkDrawableId = R.drawable.buy_selected;  
	            break;  
	        case Constant.BTN_FLAG_NEWS:  
	            checkDrawableId = R.drawable.find_selected;  
	            break;  
	        case Constant.BTN_FLAG_SETTING:  
	            checkDrawableId = R.drawable.me_selected;  
	            break;  
	        default:break;  
	        }  
	        if(mImageView != null){  
	            mImageView.setImageResource(checkDrawableId);  
	        }  
	    		    	
	    }  */
	    
	    
	    public void setChecked(int btnId){  
	    	int DrawableID=-1;
	    	
		     if(mTextView != null){  
		            mTextView.setTextColor(CHECKED_COLOR);  
		        }  
		     
		     switch(btnId){
             case R.id.btn_buy_act_main:{
            	 DrawableID=R.drawable.buy_selected;
                          break;}
             case R.id.btn_order_act_main:{
            	 DrawableID=R.drawable.order_selected;
                   break;}
             case R.id.btn_find_act_main:{
            	 DrawableID=R.drawable.find_selected;
                   break;}
             case R.id.btn_me_act_main:{
            	 DrawableID=R.drawable.me_selected;
                   break;}
                }
		     
		        if((mImageView != null)&&(DrawableID!=-1)){  
		            mImageView.setImageResource(DrawableID);  
		        }  
		    		    	
		    } 
}
